package net.oschina.app.adapter.center_message;

import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.bean.ActiveBean;
import net.oschina.app.util.CommonUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by wei03 on 2017/1/15.
 * 我---消息界面的评论界面
 */

public class CommentsAdapter extends BaseAdapter {
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(CommonUtils.getContext()).inflate(R.layout.item_comments, parent, false);
        CommentsHolder commentsHolder = new CommentsHolder(itemView);
        return commentsHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CommentsHolder commentsHolder = (CommentsHolder) holder;
        ActiveBean activeBean = (ActiveBean) mDatas.get(position);
        Glide.with(CommonUtils.getContext()).load(activeBean.getPortrait()).into(commentsHolder.mIvUserMessage);
        commentsHolder.mTvUserName.setText(activeBean.getAuthor());
        commentsHolder.mTvDate.setText(activeBean.getPubDate());
        String message = activeBean.getMessage();
        //富文本的显示
        Spanned html = Html.fromHtml(message);
        commentsHolder.mTvMsg.setText(html);
        commentsHolder.mTvObjMsg.setText(activeBean.getObjectreply().getObjectname()+" : "+
                activeBean.getObjectreply().getObjectbody());
    }


    static class CommentsHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.iv_user_message)
        CircleImageView mIvUserMessage;
        @BindView(R.id.tv_user_name)
        TextView mTvUserName;
        @BindView(R.id.tv_date)
        TextView mTvDate;
        @BindView(R.id.tv_msg)
        TextView mTvMsg;
        @BindView(R.id.tv_obj_msg)
        TextView mTvObjMsg;

        CommentsHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
